#### "Democracy and Development" ####
# authors: "Pelke, Lars"
# date: 2021-09-03
# written under "R version 34.1.1 (2021-08-10)"

#### Preliminaries ####

R.version$version.string

# clear workspace
rm(list=ls())

# set working directory
setwd("C:/Users/ba72loko/Promotion/Paper/Autocratization and Economic Well-Being/calculations_Nov_2021")


#### Preliminaries ####
library(tidyverse)
library(ggpubr)
library(haven)
library(viridis)
library(hrbrthemes)

#### Load Dataset ####

data_figure_3 <- read_dta("outputs/Step3/data_Figure.dta") 

#### Figure Step 3 ####

ggplot(data = data_figure_3, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#F4A460", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(0,60,5)) +
  scale_x_continuous(breaks=seq(0,30,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") +
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=16,face="bold"))


ggsave("outputs/Step3/Step3_Figure_5.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step3/Step3_Figure_5.eps", units= c("cm"), width = 40, height = 20, dpi = 900)


#### Figure Step 3 Robustness ####

data_figure_3_robust <- read_dta("outputs/Step3/data_Figure_robust.dta") 


ggplot(data = data_figure_3_robust, aes(x = time)) +
  geom_ribbon(aes(ymin=min95, ymax = max95), fill = "#440154FF", alpha = 0.5) +
  geom_line(aes(y=min95), color = "#999999", linetype = "dotdash", size = 1.05) +
  geom_line(aes(y=max95), linetype = "dotdash", color = "#999999", size = 1.05) +
  geom_line(aes(y=estimate), size = 1.3, color = "black") +
  geom_hline(aes(yintercept = 0), color = "red", linetype = "dashed", alpha = 0.5) +
  scale_y_continuous(breaks=seq(0,60,5)) +
  scale_x_continuous(breaks=seq(0,30,5)) +
  theme_pubr()+
  labs(x = "Year around democratization", 
       y = "Change in GDP per capita log points") +
  theme(axis.text=element_text(size=14),
        axis.title=element_text(size=16,face="bold"))


ggsave("outputs/Step3/Step3_Figure_5_robust.pdf", units= c("cm"), width = 40, height = 20, dpi = 900)
ggsave("outputs/Step3/Step3_Figure_5_robust.eps", units= c("cm"), width = 40, height = 20, dpi = 900)

